package cn.client.data

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow

class UserStateManager {
    // 使用 MutableStateFlow 存储用户 ID
    private val _userId = MutableStateFlow<Int>(-1)
    // 提供只读访问的 SharedFlow
    val userId: SharedFlow<Int> = _userId.asSharedFlow()

    // 提供一个函数来更新用户 ID
    fun setUserId(newId: Int) {
        _userId.value = newId
    }
}

// 创建 UserStateManager 的单例实例
val userStateManager = UserStateManager()